package org.suk.dp.iterator;

/**
 * Description: 具体迭代器类（倒序）<br/>
 * @version V1.0  2017/6/21 16:10  by 石冬冬(dongdong.shi@ucarinc.com) - Heil Hitler
 */
public class ConcreteIteratorDesc extends Iterator {
    private ConcreteAggregate aggregate;
    private int current = 0;

    public ConcreteIteratorDesc(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
        this.current = this.aggregate.getCount() - 1;
    }

    @Override
    Object first() {
        return this.aggregate.getItems().get(this.aggregate.getCount() - 1);
    }

    @Override
    Object next() {
        Object ret = null;
        this.current --;
        if(this.current >= 0){
            ret = this.aggregate.getItems().get(this.current);
        }
        return ret;
    }

    @Override
    boolean hasNext() {
        return !(this.current < 0);
    }

    @Override
    Object currentItem() {
        return this.aggregate.getItems().get(this.current);
    }
}
